#!/bin/bash -xv

DBNAME=phbbase
DBSCHEMA=../src/main/db/schema.sql
DBDATA=../src/main/db/data.sql

# warning
echo "Beware: This script will wipe and recreate the $DBNAME database. All previous data will be lost!!"
echo"Continue anyway? (y/n)"
read YesNo
if [ "${YesNo/Y/y}" != "y" ]; then
    exit 1
fi
# first drop old DB  + the recreate
sudo -u postgres psql << EOF
drop database $DBNAME;
create database $DBNAME;
EOF

# create schema
sudo -u postgres psql -d $DBNAME -f $DBSCHEMA
# insert data
sudo -u postgres psql -d $DBNAME -f $DBDATA